#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

vector<vector<int>> merge(vector<vector<int>>& intervals) {
    sort(intervals.begin(), intervals.end());
    vector<vector<int>> res;
    for (int i = 0; i < intervals.size(); i++)
    {
        int st = intervals[i][0], ed = intervals[i][1];
        int j = 0;
        for (j = i + 1; j < intervals.size(); j++)
        {
            if (ed >= intervals[j][0])    ed = max(ed, intervals[j][1]);
            else break;
        }
        i = j - 1;
        res.push_back({ st,ed });
    }
    return res;
}